#!/usr/bin/env bash
# node

if [[ -z "${c_node}" ]]; then
    f_info 'node: not install';
    echo > /dev/null;  return;
fi;

ins="${INS}/node";  ov=`cat "${ins}/.version" 2>/dev/null`;
if [[ "${ov}" = "${c_node}" ]]; then f_info "node: has v${c_node}";
else
    f_wait "node: v${c_node}";  n="node-v${c_node}-linux-x64";
    url="https://nodejs.org/dist/v${c_node}/${n}.tar.xz";
    n="node-${c_node}.tar";  f_down 'node' "${n}" "${url}" '1';
    cd "${INS}" || f_fail 'node: cd to INS';
    rm -rf "${ins}"* || f_fail 'node: del old';
    tar xf "${TMP}/${n}" || f_fail 'node: tar xf';
    mv "node-v${c_node}-linux-x64" "${ins}" || f_fail 'node: mv source';
    echo "${c_node}" > "${ins}/.version" || f_fail 'node: save version';
fi;

echo > /dev/null;
